package com.tyut.service.impl;


import com.tyut.mapper.RemarkMapper;
import com.tyut.pojo.Remark;
import com.tyut.service.RemarkService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 评论表 业务层
 */
@Service
@Transactional
public class RemarkServiceImpl implements RemarkService {
    @Resource
    private RemarkMapper remarkMapper;

    public List<Remark> queryListRemarkByTid(Integer tid) {
        return remarkMapper.queryListRemarkByTid(tid);
    }

    /**
     * 添加评论
     * @param remark
     */
    public boolean addRemark(Remark remark) {
        return remarkMapper.addRemark(remark) > 0;
    }

    /**
     * 删除评论
     * @param cid
     */
    public boolean deleteRemark(Integer cid) {
        return remarkMapper.deleteRemark(cid) > 0;
    }

    /**
     * 计算 景点评分的平均值
     * @return
     */
//    public Float average(Integer tid) {
//        List<Remark> remarks = remarkMapper.queryListRemarkByTid(tid);
//        Integer number = 0; //评分个数
//        float sum = 0; //评分和
//        for (Remark remark:remarks) {
//            number++;
//            sum += remark.getRscore();
//        }
//        return sum / number;
//    }

}
